﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SymWorld.Model
{
    public class Vector
    {
        // TODO Enhance accuracy
        private double _x = 0d;
        private double _y = 0d;
        private double _z = 0d;

        public Vector() { }
        public Vector(double x, double y, double z)
        {
            _x = x;
            _y = y;
            _z = z;
        }

        public double X
        {
            get { return _x; }
            set { _x = value; }
        }
        public double Y
        {
            get { return _y; }
            set { _y = value; }
        }
        public double Z
        {
            get { return _z; }
            set { _z = value; }
        }
    }
    public static class VectorExtension
    {
        public static double Distance(this Vector v1, Vector v2)
        {
            double x2 = (v1.X - v2.X)*(v1.X - v2.X);
            double y2 = (v1.Y - v2.Y)*(v1.Y - v2.Y);
            double z2 = (v1.Z - v2.Z)*(v1.Z - v2.Z);

            return Math.Sqrt(x2 + y2 + z2);
        }
        public static Vector Difference(this Vector v1, Vector v2)
        {
            return new Vector(v1.X - v2.X, v1.Y - v2.Y, v1.Z - v2.Z);
        }
        public static Vector Sum(Vector v1, Vector v2)
        {
            return new Vector(v1.X + v2.X, v1.Y + v2.Y, v1.Z + v2.Z);
        }
        public static Vector Normalized(this Vector v)
        {
            double length = VectorExtension.Length(v);
            return new Vector(v.X / length, v.Y / length, v.Z / length);
        }
        public static double Length(this Vector v)
        {
            return VectorExtension.Distance(v, new Vector());
        }
        public static Vector Multiply(this Vector v, double k)
        {
            return new Vector(v.X * k, v.Y * k, v.Z * k);
        }
    }
}
